(function($, window, undefined) {
    var rss = window.rss;
    var localInfo = window.localInfo;
    var reqClientType = localInfo.reqClientType;
    var ec = window.ec;

    //上传头像弹框
    var uploadIframe = '<iframe name="left" id="rightMain" src="' + localHttps + '/portal/userCenter/uploadHeadPic_dialog.html' + localInfo.urlQurey + '" frameborder="false" scrolling="no" style="border:none;" width="486" height="485" allowtransparency="true"></iframe>';
    function uploadPicDialog() {
        $('<div>').Dialog({
            title : rss.uploadAvatar,
            titleUnderline : false,
            btnRight : false,
            btnLeft : false,
            html : uploadIframe,
            beforeAction : function() {
                var self = this;
                $(document).on("click", ".close", function() {
                    self.hide();
                });
            }
        }).Dialog('show');
    }


    $(document).on("click", "#uploadImg", function() {
    	if(localInfo.siteID == currentSiteID) {  //不是跨站点时
    		uploadPicDialog();
    		$('.global_dialog_confirm_main').width(550);
    		$('.global_dialog_confirm_nor').hide();
    		//按钮
    		$('.ellipsis').append('<div class="btn-no close"></div>');
    		//关闭按钮
    	}
    }).on("click", "#uploadImgDiv", function() {
    	if(localInfo.siteID == currentSiteID) {  //不是跨站点时
	        uploadPicDialog();
	        $('.global_dialog_confirm_main').width(550);
	        $('.global_dialog_confirm_nor').hide();
	        //按钮
	        $('.ellipsis').append('<div class="btn-no close"></div>');
	        //关闭按钮
    	}
    });

    $(document).on("click", "#nickNameLink", function() {
        var htmlStr = '<div class="dinput"><input id="nicknametext" type="text"></div><p id="error_info"></p>';
        htmlStr += '';
        var option = {
            title : rss.nickname,
            btnRight : {
                text : rss.set,
                fn : function() {
                    var self = this;
                    if (!ec.form.validator($("#nicknametext"), true)) {
                        return false;
                    }

                    var userInfo = {
                        nickName : $("#nicknametext").val().trim()
                    };
                    updateUserInfo(userInfo, function() {
                        self.hide();
                    });

                }
            },
            btnLeft : {
                text : rss.cancel_btn,
                fn : function() {
                }
            },
            html : htmlStr,
            beforeAction : function() {
                ec.form.input.label.defaults.ifRight="10px";
                ec.form.input.label($('#nicknametext'), rss.notnull);
                var self = this;
                self.disabled();
                $("#nicknametext").val(localInfo.nickName);
                $('#nicknametext').on('keyup change', function() {
                    if ($("#nicknametext").val().trim() != localInfo.nickName) {
                        self.enable();
                    } else {
                        self.disabled();
                    }
                });
               
            }
        };
        $("<div>").Dialog(option).Dialog("show");
        checkNickName();
    });
    
    // 针对论坛昵称进行调整 begin
    $(document).on("click", "#forumNickNameLink", function() {
        var htmlStr = '<p>' + rss.modifyUserInfo_forum_nickname_tips + '</p><div class="dinput"><input id="forumnicknametext" type="text"></div><p id="error_info"></p>';
        htmlStr += '';
        var option = {
            title : rss.forumnicknameTitle,
            btnRight : {
                text : rss.set,
                fn : function() {
                    var self = this;
                    if (!ec.form.validator($("#forumnicknametext"), true)) {
                        return false;
                    }

                    var userInfo = {
                    		uniquelyNickname: $("#forumnicknametext").val().trim()
                    };
                    
                    updateUserInfo(userInfo, function() {
                        self.hide();
                    });

                }
            },
            btnLeft : {
                text : rss.cancel_btn,
                fn : function() {
                }
            },
            html : htmlStr,
            beforeAction : function() {
                ec.form.input.label.defaults.ifRight="10px";
                ec.form.input.label($('#forumnicknametext'), rss.notnull);
                var self = this;
                self.disabled();
                $("#forumnicknametext").val(localInfo.forumNickName);
                $('#forumnicknametext').on('keyup change', function() {
                    if ($("#forumnicknametext").val().trim() != localInfo.forumNickName) {
                        self.enable();
                    } else {
                        self.disabled();
                    }
                });
               
            }
        };
        $("<div>").Dialog(option).Dialog("show");
        checkForumNickName();
    });
    // 针对论坛昵称进行调整 end

    $(document).on("click", "#genderLink", function() {
        var htmlStr = '<input type="hidden" id="sex" name="sex" value="0">';
        htmlStr += '<div class="dbox">';
        htmlStr += '<div class="mkcl"><b class="radio ron r" data-value="0" data-group="sex" data-check="true"></b><p class="item">' + rss.gender_male + '</p></div>';
        htmlStr += '<div class="mkcl"><b class="radio roff r" data-value="1" data-group="sex"></b><p class="item">' + rss.gender_female + '</p></div>';
        htmlStr += '<div class="mkcl"><b class="radio roff r" data-value="2" data-group="sex"></b><p class="item">' + rss.gender_secret + '</p></div>';
        htmlStr += '<div class="mkcl"><b class="radio roff r" data-value="-1" data-group="sex"></b><p class="item">'+rss.gender_unknown+'</p></div>';
        htmlStr += '</div>';
        var option = {
            title : rss.sex,
            btnRight : {
                text : rss.confirm_btn,
                fn : function() {
                    var self = this;
                    var userInfo = {
                        gender : $("#sex").val()
                    };
                    updateUserInfo(userInfo, function() {
                        self.hide();
                    });

                }
            },
            btnLeft : {
                text : rss.cancel_btn,
                fn : function() {
                }
            },
            html : htmlStr,
            beforeAction : function() {
                var self = this;

                $('#sex').on('change', function() {
                    if ($("#sex").val() != localInfo.gender) {
                        self.enable();
                    } else {
                        self.disabled();
                    }
                });
                var selectorStr = ".dbox [data-value=" + localInfo.gender + "]";
                $(selectorStr).trigger("check");
                self.disabled();
            }
        };

        $("<div>").Dialog(option).Dialog("show");

    });

    $(document).on("click", "#cityLink", function() {
        var htmlStr = '<div id="cityDiv">';
        htmlStr += '<div class="ddrop" id="provinceList"></div>';
        htmlStr += '<div class="ddrop" id="cityList"></div>';
        htmlStr += '</div>';
        var provinceitems = [];
        var cityitems = [];
        initProvince(provinceitems);
        var option = {
            title : rss.city,
            btnRight : {
                text : rss.confirm_btn,
                fn : function() {
                    var self = this;
                    if (!ec.form.validator($("#cityDiv"), true)) {
                        return false;
                    }
                    var userInfo = {
                        province : $("#provinceList span").text(),
                        city : $("#cityList span").text()
                    };
                    var displayVal = userInfo.province+userInfo.city;
                    updateUserInfo(userInfo, function() {
                        self.hide();
                    });

                }
            },
            btnLeft : {
                text : rss.cancel_btn,
                fn : function() {
                }
            },
            html : htmlStr,
            beforeAction : function() {
                var self = this;
                $('#provinceList').DropList({
                    items : provinceitems,
                    onChange : function(key, value) {
                        $('#provinceList input').val(key);
                        cityitems = [];
                        initCity(key, cityitems);
                        $('#cityList').html('');
                        $('#cityList').DropList({
                            items : cityitems,
                            onChange : function(key, value) {
                                $('#cityList input').val(key);
                            }
                        });
                        if ($('#provinceList span').text() != localInfo.province || $('#cityList span').text() != localInfo.city) {
                            self.enable();
                        } else {
                            self.disabled();
                        }
                    }
                }).DropList("select", getProvinceIDByName(localInfo.province) == "" ? 11 : getProvinceIDByName(localInfo.province));
                $('#cityList span').val(localInfo.city);
                initCity($('#provinceList input').val(), cityitems);
                var city;
                if(localInfo.city==undefined || localInfo.city=="")
                {
                	city=cityitems[0].label;
                }
                else
                {
                	city=localInfo.city;
                }
                
                $('#cityList').DropList({
                    items : cityitems,
                    onChange : function(key, value) {
                        $('#cityList input').val(key);
                        if ($('#provinceList span').text() != localInfo.province || $('#cityList span').text() != localInfo.city) {
                            self.enable();
                        } else {
                            self.disabled();
                        }
                    }
                }).DropList("select", getCityIDByName($('#provinceList span').text(),city));

                self.disabled();
            }
        };
        $("<div>").Dialog(option).Dialog("show");
        checkCity();

    });

    /*
     $(document).on("click", "#signatureLink", function() {
     var htmlStr = '<div class="dinput"><input id="signatureText" type="text" placeholder="个性签名"></div><p id="error_info"></p>';
     dialog({
     title: "个性签名",
     btnRight: {
     text:rss.confirm_btn,
     fn: function() {
     var userInfo = {
     reqClientType:reqClientType,
     signature:$("#signatureText").val()
     }
     updateUserInfo(userInfo,$("#signature"),userInfo.signature);
     }
     },
     btnLeft: {
     text:rss.cancel_btn,
     fn: function() {}
     },
     html: htmlStr
     });

     });*/

    /*
     $(document).on("click", "#nameLink", function() {
     var htmlStr = '<div class="dinput"><input id="firtnameText" type="text" placeholder="姓"></div>';
     htmlStr+='<div class="dinput"><input id="secondnameText" type="text" placeholder="名"></div>';
     htmlStr+='<p id="error_info"></p>';
     dialog({
     title: "姓名",
     btnRight: {
     text: rss.confirm_btn,
     fn: function() {
     var userInfo = {
     reqClientType:reqClientType,
     firstname:$("#firstnameText").val(),
     secondname:$("#secondnameText").val()
     }
     var displayVal = userInfo.firstname + " "+ userInfo.secondname;
     updateUserInfo(userInfo,$("#name"),displayVal);
     }
     },
     btnLeft: {
     text: rss.cancel_btn,
     fn: function() {}
     },
     html: htmlStr
     });

     });
     */

    $(document).on("click", "#birthdayLink", function() {
        var htmlStr = '<div id="birthdayDiv">';
        htmlStr += '<div id="yearList"></div>';
        htmlStr += '<div id="monthList"></div>';
        htmlStr += '<div id="dayList"></div>';
        htmlStr += '</div>';
        var myDate = new Date();
        var thisYear = myDate.getFullYear();
        var startyear = 1900;
        var yearitems = [];
        for (var i = thisYear; i >= startyear; i--) {
            var yearitem = {
                value : i,
                label : i
            };
            
            yearitems.push(yearitem);
        }

        var monthitems = [];
        for (var j = 1; j <= 12; j++) {
            var monthitem = {
                value : j,
                label : j
            };
            monthitems.push(monthitem);
        }

 
     

        var option = {
            title : rss.birthdayTitle,
            btnRight : {
                text : rss.confirm_btn,
                fn : function() {
                    var self = this;
                    if (!ec.form.validator($("#birthdayDiv"), true)) {
                        return false;
                    }

                    var year = $("#yearList input").val();
                    var month = $("#monthList input").val() < 10 ? "0" + $("#monthList input").val() : $("#monthList input").val();
                    var day = $("#dayList input").val() < 10 ? "0" + $("#dayList input").val() : $("#dayList input").val();

                    var thisYear = new Date().getFullYear();
                    var birthDate = localInfo.birthDate;
                    
                    
                    var oldYear = birthDate.substring(0, 4);
                    var oldMonth = birthDate.substring(4,6);
                    var oldDay = birthDate.substring(6,8);
                    
                    
                    // 首先判定当前年龄属于什么范围
                    var isChildFlag=isChildren(oldYear,oldMonth,oldDay);
                    var isAdultFlag=isAdult(oldYear,oldMonth,oldDay);
                    var isMinorFlag=false;
                    
                    if(isChildFlag == false && isAdultFlag == false)
                    {
                    	isMinorFlag=true;
                    }
                    
                    
                     if (localInfo.accountSiteID == '7') {                      
                        
                    	
                    	// 如果为儿童，那么不能调整为非儿童
                    	if(isChildFlag)
                    	{
                    		// 10000606
                    		if (!isChildren(year, month, day)) 
                    		{
                                showError($(".errortip"), rss.uc_infochangenochild_error);
                                return;
                            }
                    	}
                    	
                    	// 如果为非成年人，不能调整为非非成年人
                    	if(isMinorFlag)
                    	{
                    		// 10000607
                    		if(isChildren(year, month, day))
                    		{
                    			showError($(".errortip"), rss.uc_infochangetochild_error);
                    			return;
                    		}
                    		
                    		// 10000608
                    		if(isAdult(year, month, day))
                    		{
                    			showError($(".errortip"), rss.uc_infochangetoadult_error);
                    			return;
                    		}
                    	}
                    	
                    	// 如果为成年人，不能调整为非成年人
                    	if(isAdultFlag)
                    	{
                    		// 10000609
                    		if(!isAdult(year, month, day))
                    		{
                    			showError($(".errortip"), rss.uc_infochangenoadult_error);
                    			return;
                    		}
                    	}
                    	
                     }
          
               
                    var birthday = year + month + day;
                    var userInfo = {
                        birthDate : birthday
                    };
                    updateUserInfo(userInfo, function() {
                        self.hide();
                    });

                }
            },
            btnLeft : {
                text : rss.cancel_btn,
                fn : function() {
                }
            },
            html : htmlStr,
            beforeAction : function() {
                var self = this;
                var birthDate = localInfo.birthDate;
                var oldYear = birthDate.substring(0, 4);
                var oldMonth = birthDate.substring(4, 6);
                var oldDay = birthDate.substring(6, 8);
                $('#yearList').DropList({
                    items : yearitems,
                    onChange : function(key, value) {
                        $('#yearList input').val(key);
                        $('#monthList').DropList("select",1);
                        changeDayDropList($('#yearList input').val(),1);
                        if ($('#yearList input').val() != parseInt(oldYear) || $('#monthList input').val() != parseInt(oldMonth) || $('#dayList input').val() != parseInt(oldDay)) {
                            self.enable();
                        } else {
                            self.disabled();
                        }
                        
                    }
                }).DropList("select", (oldYear == "" || oldYear == undefined) ? thisYear : parseInt(oldYear));
                
                $('#monthList').DropList({
                    items : monthitems,
                    onChange : function(key, value) {
                        $('#monthList input').val(key);
                        changeDayDropList($('#yearList input').val(),$('#monthList input').val());
                        if ($('#yearList input').val() != parseInt(oldYear) || $('#monthList input').val() != parseInt(oldMonth) || $('#dayList input').val() != parseInt(oldDay)) {
                            self.enable();
                        } else {
                            self.disabled();
                        }
                        
                    }
                }).DropList("select", (oldMonth == "" || oldMonth == undefined) ? 1 : parseInt(oldMonth));
                
                var dayitems = setDays($('#yearList input').val(),$('#monthList input').val());
                
                $('#dayList').DropList({
                    items : dayitems,
                    onChange : function(key, value) {
                        $('#dayList input').val(key);
                        if ($('#yearList input').val() != parseInt(oldYear) || $('#monthList input').val() != parseInt(oldMonth) || $('#dayList input').val() != parseInt(oldDay)) {
                            self.enable();
                        } else {
                            self.disabled();
                        }
                    }
                }).DropList("select", (oldDay == "" || oldDay == undefined) ? 1 : parseInt(oldDay));
                self.disabled();
            }
        };

        $("<div>").Dialog(option).Dialog("show");

    });
    function changeDayDropList(year,month) {
        $('#dayList').html("");
        $('#dayList').DropList({
           items : setDays($('#yearList input').val(),$('#monthList input').val()),
           onChange : function(key, value) {
              $('#dayList input').val(key);
          }
        }).DropList("select",1);
    }
    
    function setDays(year,month) {
        var maxDay = 31;
        var dayitems = [];
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
            maxDay = 31;
        } else if (month == 2) {
            if (isLeapYear(year)) {
                maxDay = 29;
            } else {
                maxDay = 28;
            }
        } else {
            maxDay = 30;
        }
                
        for (var k = 1; k <= maxDay; k++) {
            var dayitem = {
                value : k,
                label : k
            };
            dayitems.push(dayitem);
        }
        return dayitems;
    }
    
    function isLeapYear(year) {
        return (0 == parseInt(year) % 4 && (parseInt(year) % 100 != 0 || parseInt(year) % 400 == 0));
    }

    // 检查论坛昵称,论坛昵称的规则需要考量一下。
    function checkForumNickName(){
    	var forumnickname = $("#forumnicknametext");
    	
    	ec.form.validator.bind(forumnickname,{
    		type : ["length", "isNullstr","forumnicknameformat"],
            trim : true,
            validOnChange : true,
            min : 0,
            max : 20,
            msg_ct : "#error_info",
            msg : {
                length :rss.forumNicknameLengthTip,
                isNullstr :rss.error_70005002_2,
                forumnicknameformat : rss.forumNicknameFormatTip
            }
    	});
    	
    	ec.form.validator.register("isNullstr", function(b_val, a) {
        	if ($.trim(b_val).toLowerCase() == "null") {
        		return false;
        	}
        	var regex2=/^huafans.*$|^huafen.*$/;
	        return !regex2.test(b_val);
        	
        });
    	
    	
        ec.form.validator.register("forumnicknameformat", function(b_val, a) {
	        if ($.trim(b_val) == "") {
	            return false;
	        }
	        
	        var regex1=/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/;
	        
	        return regex1.test(b_val);
	            
        });
    }
    
    function checkNickName() {
        var nickname = $("#nicknametext");
        ec.form.validator.bind(nickname, {
            type : ["strLength", "isNullstr", "nicknameformat"],
            trim : true,
            validOnChange : true,
            min : 0,
            max : 20,
            msg_ct : "#error_info",
            msg : {
            	strLength :rss.nicknameLengthTip,
                isNullstr :rss.error_70005002,
                nicknameformat : rss.nicknameFormatTip
            }
        });

        ec.form.validator.register("isNullstr", function(b_val, a) {
        	if ($.trim(b_val).toLowerCase() == "null") {
        		return false;
        	}
        	return true;
        });
        ec.form.validator.register("nicknameformat", function(b_val, a) {
            if ($.trim(b_val) == "") {
                return true;
            }
            var regx = /^([^\u0000-\u001f<>\,\;\/\%\&\'\"\(\)\[\]\{\}\\])+$/g;
            return regx.test(b_val);
        });
    }

    function checkCity() {
        var provincetext = $("#provincetext");
        var citytext = $("#citytext");
        ec.form.validator.bind(provincetext, {
            type : ["require"],
            trim : false,
            validOnChange : true,
            msg_ct : "#error_info_province",
            msg : {
                require : rss.provinceChoose
            }
        });
        ec.form.validator.bind(citytext, {
            type : ["require"],
            trim : false,
            validOnChange : true,
            msg_ct : "#error_info_city",
            msg : {
                require : rss.cityChoose
            }
        });
    }
   
    function isAdult(year, month, day) {
        var adultDay = new Date(year, parseInt(month) - 1, day);
        adultDay.setFullYear(parseInt(year) + 18);
        var adultDayTime = adultDay.getTime();
        var thisDayTime = new Date().getTime();
        return adultDayTime <= thisDayTime;
    }
    
    function isChildren(year, month, day) {
        var childrenDay = new Date(year, parseInt(month) - 1, day);
        childrenDay.setFullYear(parseInt(year) + 13);
        var childrenDayTime = childrenDay.getTime();
        var thisDayTime = new Date().getTime();
        return childrenDayTime >= thisDayTime;
    }

    function checkBirthday() {
        var yeartext = $("#yeartext");
        var monthtext = $("#monthtext");
        var daytext = $("#daytext");

        ec.form.validator.bind(yeartext, {
            type : ["require"],
            trim : false,
            validOnChange : true,
            msg_ct : "#error_info_year",
            msg : {
                require : rss.yearInputTip
            }
        });

        ec.form.validator.bind(monthtext, {
            type : ["require"],
            trim : false,
            validOnChange : true,
            msg_ct : "#error_info_month",
            msg : {
                require : rss.monthInputTip
            }
        });

        ec.form.validator.bind(daytext, {
            type : ["require"],
            trim : false,
            validOnChange : true,
            msg_ct : "#error_info_day",
            msg : {
                require : rss.dayInputTip
            }
        });
    }

    function checkRadio(obj, check) {
        if (check) {
            obj.removeClass("roff").addClass("ron");
        } else {
            obj.removeClass("ron").addClass("roff");
        }
        obj.data("check", check);
    }

    var formatDate = function(date) {
        if (date) {
            var year = date.substring(0, 4);
            var month = date.substring(4, 6);
            var day = date.substring(6, 8);
            var formatDateStr = year + "-" + month + "-" + day;
            return formatDateStr;
        }
        return "";
    };
    var displayGender = function(gender) {
        if (gender == '-1') {
            $("#gender").text(rss.gender_unknown);
        } else if (gender == '0') {
            $("#gender").text(rss.gender_male);
        } else if (gender == '1') {
            $("#gender").text(rss.gender_female);
        } else if (gender == '2') {
            $("#gender").text(rss.gender_secret);

        }
    };
    var updateUserInfo = function(userInfo, callback) {
        var method = "updateUserInfo";
        var param = {
            "userInfo" : JSON.stringify(userInfo),
            "reqClientType" : reqClientType,
            "pageToken" : localInfo.pageToken
        };
        ajaxHandler(method, param, function(data) {
            var flag = data.isSuccess;
            if (flag == "1") {
                callback();
                window.location.reload();
            } else {
            	
                if (data.errorCode == '70005002' && userInfo.nickName!=undefined) {
                    showError($(".errortip"), rss.error_70005002);
                }else if(data.errorCode == '10002074' && userInfo.uniquelyNickname!=undefined) {
                	showError($(".errortip"), rss.forumNicknameFormatTip);
                }else if(data.errorCode == '70005002' && userInfo.uniquelyNickname!=undefined) {
                    showError($(".errortip"), rss.error_70005002_2);
                } else if (data.errorCode == '70005005') {
                    showError($(".errortip"), rss.error_70005005);
                }else if (data.errorCode == '70007005') {
                    showError($(".errortip"), rss.error_70007005);
                }else if (data.errorCode == '10000606') {
                	showError($(".errortip"), rss.uc_infochangenochild_error);
                }else if (data.errorCode == '10000607') {
                	showError($(".errortip"), rss.uc_infochangetochild_error);
                }else if (data.errorCode == '10000608') {
                	showError($(".errortip"), rss.uc_infochangetoadult_error);
                }else if (data.errorCode == '10000609') {
                	showError($(".errortip"), rss.uc_infochangenoadult_error);
                }else if (data.errorCode == '10000001') {
                    showError($(".errortip"), rss.error_10000001);
                }  else if (data.errorCode == "70005003") {
                    showError($(".errortip"), rss.error_70005003);
                } else if (data.errorCode == "70001201") {
                    showError($(".errortip"), rss.error_70001201);
                } else if (data.errorCode == "10000604") {
                    showError($(".errortip"), rss.error_10000604);
                } else {
                   showError($(".errortip"), rss.failUpdateUserinfo); 
                }
            }
        }, function(data) {
            showError($(".errortip"), rss.bg_error);
        }, true, "JSON");
    };

    function getProvinceIDByName(provinceName){
    	var provinces = areaJson.provinces;
    	var provinceID="";
    	$.each(provinces, function(i, value) {
    		if(value.name==provinceName)
    		{
    			provinceID=value.id;
    		}
    	});
    	return provinceID;
    }
    
    function initProvince(items) {
        var provinces = areaJson.provinces;
        $.each(provinces, function(i, value) {
            var item = {
                value : value.id,
                label : value.name
            };
            items.push(item);
        });
    }
    
    function getCityIDByName(provinceName,cityName){
    	var provinces = areaJson.provinces;
    	
    	var province;
    	
    	for (var p = 0; p < provinces.length; p++) {
    		if(provinces[p].name==provinceName)
    		{
    			province=provinces[p];
    			break;
    		}
    	}
    	
    	var citys=province.citys;
    	
    	var cityID;
    	
    	for(var i=0;i<citys.length;i++)
    	{
    		var city=citys[i];
    		for(var j in city)
    		{
    			if(city[j]==cityName)
    			{
    				cityID=j;
    				return parseInt(cityID);
    			}
    		}
    	}
    	
    }

    function initCity(provinceID, items) {
        var provinces = areaJson.provinces;
        for (var p = 0; p < provinces.length; p++) {
            var province = provinces[p];
            if (province.id == provinceID) {
                var citys = province.citys;
                for (var i = 0; i < citys.length; i++) {
                    var city = citys[i];
                    for (var j in city) {
                        //items[j]=city[j];
                        var item = {
                            value : parseInt(j),
                            label : city[j]
                        };
                        items.push(item);
                    }
                }
                break;
            }
        }
    }

    function displayCity(provinceId, cityId) {
        var provinces = areaJson.provinces;
        var displayStr = "";
        for (var p = 0; p < provinces.length; p++) {
            var province = provinces[p];
            if (province.id == provinceId) {
                displayStr = province.name;
                var citys = province.citys;
                for (var j = 0; j < citys.length; j++) {
                    var city = citys[j];
                    for (var i in city) {
                        if (i == cityId) {
                            displayStr += city[i];
                            return displayStr;
                        }
                    }
                }
            }
        }
        return displayStr;
    }


    window.displayGender = displayGender;
    window.displayCity = displayCity;
    window.formatDate = formatDate;
})(jQuery, window); 